package com.sky.controller.admin;


import com.sky.dto.CategoryPageQueryDTO;
import com.sky.pojo.Category;
import com.sky.result.Result;
import com.sky.service.admin.CategoryService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//分类管理页面

@RestController
@RequestMapping("/admin/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;




    //添加新增菜品分来和新增套餐分类

    @PostMapping
    @ApiOperation("添加新增菜品分来和新增套餐分类")
    public Result insertCategory(@RequestBody Category category){
        categoryService.insertCategoryService(category);
        return Result.success();
    }


   // 进行菜品套餐分类页面分页查询-name模糊查询
    @GetMapping("/page")
    @ApiOperation("进行菜品套餐分类页面分页查询-name模糊查询")
     public  Result selectCategory(CategoryPageQueryDTO categoryPageQueryDTO){
        return Result.success(categoryService.selectCategoryService(categoryPageQueryDTO));

     }


    //    根据id删除行数据
     @DeleteMapping
     @ApiOperation("根据id删除行数据")
    public Result deleteCategory(Long id){
        categoryService.deleteCategoryService(id);

        return Result.success();
     }


     //修改行数据
     @PutMapping
     @ApiOperation("修改行数据")
    public Result updateCategory(@RequestBody Category category){
        categoryService.updateCategoryServise(category);
        return Result.success();
     }



    //    启用或禁用分类行数据status
     @PostMapping("/status/{status}")
     @ApiOperation("启用或禁用分类行数据status")
    public Result ResultupdateCategory(@PathVariable Integer status,Integer id){
        categoryService.updateCategoryStatus(status,id);
        return Result.success();

     }



    //查询菜品分类名称给进行菜品管理添加
  @GetMapping("/list")
  @ApiOperation("查询菜品分类名称给进行菜品管理添加")
    public Result selectName(Integer type){

      List<Category> categories = categoryService.selectNameService(type);
      return Result.success(categories);

  }



}
